<template>
	<view>
		<swiper circular autoplay :interval="3000" :duration="500" indicator-dots
			indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#0b65ec" style="height:350rpx">
			<swiper-item v-for="(item,index) in bannerList" :key="index">
				<navigator>
					<image :src="item" alt="" mode="widthFix" style="width: 100%;" />
				</navigator>
			</swiper-item>
		</swiper>
		<view style="padding: 20rpx;">
			<view class="box">
				<uni-notice-bar scrollable single show-icon :text="suspendNotice" color="#000"
					background-color="#fff" />
			</view>
		</view>
		<view style="display: flex;background-color:#fff;border-radius: 10rpx; padding: 0 20rpx;">
				<scroll-view scroll-y="true" style="height: 55vh;width:320rpx;text-align: center;">
				<view v-for="(item,index) in departmentList" :key="index" class="department-item"
					:class="{'department-active':index===activeDepartmentIndex}"
					@click="loadSecondClassDepartmentList(index)">
                    {{item.name}}
				</view>
				</scroll-view>
				<scroll-view scroll-y="true" style="height: 55vh;text-align: center;">
				<view v-for="item in secondClassDepartmentList" :key="item.id" class="secondClassDepartment-item" @click="goToAppointmentRegister(item.id)">
					{{item.name}}
				</view>
				</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bannerList: ['http://47.116.78.187:8088/file/5c32be5ee8e7473d9eb9f55ca6ac06f7.png',
					'http://47.116.78.187:8088/file/90ec561537704ff49ab922cf2960884d.png',
					'http://47.116.78.187:8088/file/21b36bf92e1449c09a296d8972848b52.png'
				],
				suspendNoticeList: [],
				suspendNotice: '',
				departmentList: [],
				secondClassDepartmentList: [],
				activeDepartmentIndex: 0,
			}
		},
		onLoad() {
			this.load();
		},
		methods: {
			load() {
				this.$request.get('/appointment-scheduler/selectSuspendNoticeList').then(res => {
					this.suspendNoticeList = res.data || [];
					if (this.suspendNoticeList.length) {
						let i = 0;
						this.suspendNotice = this.suspendNoticeList[i].doctorName + '医生（' + this.suspendNoticeList[i]
							.departmentName + '）：' + this.suspendNoticeList[i].workDate + this.suspendNoticeList[i]
							.dayPart + '停诊';
						i++;
						if (this.suspendNoticeList.length > 1) {
							setInterval(() => {
								if (i === this.suspendNoticeList.length) {
									i = 0;
								}
								this.suspendNotice = this.suspendNoticeList[i].doctorName + '医生（' + this
									.suspendNoticeList[i].departmentName + '）：' + this.suspendNoticeList[i]
									.workDate + this.suspendNoticeList[i].dayPart + '停诊';
								i++;
							}, 12000)
						}
					}
				})


				this.$request.get('/department/selectAll').then(res => {
					this.departmentList = res.data;
					this.secondClassDepartmentList = this.departmentList[0].secondClassDepartmentList;
				})
			},
			loadSecondClassDepartmentList(index) {
				this.activeDepartmentIndex = index;
				this.secondClassDepartmentList = this.departmentList[this.activeDepartmentIndex]
					.secondClassDepartmentList != null ? this.departmentList[this.activeDepartmentIndex]
					.secondClassDepartmentList : [];
					console.log(this.secondClassDepartmentList)
			},
			goToAppointmentRegister(departmentId){
				uni.navigateTo({
					url: '/pages/appointmentRegister/appointmentRegister?departmentId='+departmentId
				})
			}
		}
	}
</script>

<style>
	.box {
		background-color: #fff;
		border-radius: 10rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, .1);
	}

	.department-item {
		padding: 15rpx;
		background-color: #eee;
	}
	
	.secondClassDepartment-item {
		padding: 15rpx;
		padding-left: 10rpx;
	}

	.department-active {
		background-color: #fff;
		color: #0b65ec;
		border-left: 5rpx solid orange;
	}
	
	scroll-view ::-webkit-scrollbar {
	   display:none;
	   width:0;
	   height:0;
	   color:transparent;
	}
</style>